package AIEngine;

public class PreferencesAI {

	/**
	 * Shows if a cell in a array is empty
	 * @param cell <=> array[x][y]
	 * @return true if the cell is empty otherwise false
	 */
	public static boolean isEmpty(int cell) {
		if (Math.abs(cell) != 1) {
			return true;
		} else {
			return false;
		}
	}


	/**
	 * Transforms a boolean value to a integer value
	 *
	 * @param black paylerflag
	 * @return -1 if black is true and 1 if black is false
	 */
	public static int colorToInt(boolean black) {
		if (black) {
			return -1;
		} else {
			return 1;
		}
	}


    /**
     * Sums up all preference values from a array
     *
     * @param field is the targetarray
     * @param black is the playerflag
     * @return value a integer value
     */
    static int getFullValue(int[][] field, boolean black) {
        int value = 0;
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                if (Math.abs(field[i][j]) != 1) {
                    value += field[i][j];
                }
            }
        }

        return value;
    }


	/**
	 * Shows if a cell in a array is flaged with a preferencevalue
	 *
	 * @param cell  <=> array[x][y]
	 * @return true if ther is a value, false if the cell is empty
	 */
	public static boolean haveAPreference(int cell) {
		if (Math.abs(cell) != 1 && cell != 0) {
			return true;
		} else {
			return false;
		}
	}

	
	public static void searchTwoInARow(int[][] field, boolean black) {

		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 5; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1])) {
					if (j < 4 && j > 0 ){
						if(isEmpty(field[i][j - 1])) {
							if(haveAPreference(field[i][j-1])){
								field[i][j-1]= Math.abs(3 * field[i][j] * field[i][j-1]) * colorToInt(black);
							}else{
								field[i][j-1]=3*field[i][j];
							}
						}
						if(isEmpty(field[i][j + 2])) {
							if(haveAPreference(field[i][j+2])){
								field[i][j+2]= Math.abs(3 * field[i][j] * field[i][j+2]) * colorToInt(black);
							}else{
								field[i][j+2]=3*field[i][j];
							}
						}
					} else {
						if (j==0 && isEmpty(field[i][j + 2])) {
							if(haveAPreference(field[i][j+2])){
								field[i][j+2]= Math.abs(3 * field[i][j] * field[i][j+2]) * colorToInt(black);
							}else{
								field[i][j+2]=3*field[i][j];
							}
						}
						
						if ((j==4) && isEmpty(field[i][j - 1])) {
							if(haveAPreference(field[i][j-1])){
								field[i][j-1]= Math.abs(3 * field[i][j] * field[i][j-1]) * colorToInt(black);
							}else{
								field[i][j-1]=3*field[i][j];
							}
						}
					}

				}
			}
		}
	}




	public static void searchTwoInAColumn(int[][] field, boolean black) {

		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 6; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j])) {
					if (i < 4 && i > 0){
						if(isEmpty(field[i - 1][j])) {
							if(haveAPreference(field[i-1][j])){
								field[i-1][j]= Math.abs(3 * field[i][j] * field[i-1][j]) * colorToInt(black);
							}else{
								field[i-1][j]=3*field[i][j];
							}
						}
						
						if(isEmpty(field[i + 2][j])) {
							if(haveAPreference(field[i+2][j])){
								field[i+2][j]= Math.abs(3 * field[i][j] * field[i+2][j]) * colorToInt(black);
							}else{
								field[i+2][j]=3*field[i][j];
							}
						}
					} else {
						if (i==0 && isEmpty(field[i + 2][j])) {
							if(haveAPreference(field[i+2][j])){
								field[i+2][j]= Math.abs(3 * field[i][j] * field[i+2][j]) * colorToInt(black);
							}else{
								field[i+2][j]=3*field[i][j];
							}
						}
						if (i==4 && isEmpty(field[i - 1][j])) {
							if(haveAPreference(field[i-1][j])){
								field[i-1][j]= Math.abs(3 * field[i][j] * field[i-1][j]) * colorToInt(black);
							}else{
								field[i-1][j]=3*field[i][j];
							}
						}
					}
				}
			}
		}

	}



	public static void searchTwoInADiagonal(int[][] field, boolean black) {

		for(int j = 0 ; j < 5 ; j++){
			for(int i = 0 ; i < 5 ; i++){
				if(i>0 && i<4 && j>0 && j<4 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i+2][j+2])) {
						if(haveAPreference(field[i+2][j+2])){
							field[i+2][j+2]= Math.abs(3 * field[i][j] * field[i+2][j+2]) * colorToInt(black);
						}else{
							field[i+2][j+2]=3*field[i][j];
						}
					}
					if (isEmpty(field[i-1][j-1])) {
						if(haveAPreference(field[i-1][j-1])){
							field[i-1][j-1]= Math.abs(3 * field[i][j] * field[i-1][j-1]) * colorToInt(black);
						}else{
							field[i-1][j-1]=3*field[i][j];
						}
					}
				}

				if(i==0 && j<4 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i+2][j+2])) {
						if(haveAPreference(field[i+2][j+2])){
							field[i+2][j+2]= Math.abs(3 * field[i][j] * field[i+2][j+2]) * colorToInt(black);
						}else{
							field[i+2][j+2]=3*field[i][j];
						}
					}
				}

				if(i==4 && j>0 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i-1][j-1])) {
						if(haveAPreference(field[i-1][j-1])){
							field[i-1][j-1]= Math.abs(3 * field[i][j] * field[i-1][j-1]) * colorToInt(black);
						}else{
							field[i-1][j-1]=3*field[i][j];
						}
					}
				}

				if(j==0 && i<4 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i+2][j+2])) {
						if(haveAPreference(field[i+2][j+2])){
							field[i+2][j+2]= Math.abs(3 * field[i][j] * field[i+2][j+2]) * colorToInt(black);
						}else{
							field[i+2][j+2]=3*field[i][j];
						}
					}
				}

				if(j==4 && i>0 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j+1]){
					if (isEmpty(field[i-1][j-1])) {
						if(haveAPreference(field[i-1][j-1])){
							field[i-1][j-1]= Math.abs(3 * field[i][j] * field[i-1][j-1]) * colorToInt(black);
						}else{
							field[i-1][j-1]=3*field[i][j];
						}
					}
				}
			}
		}

		for(int j = 5 ; j > 0; j--){
			for(int i = 0 ; i < 5 ; i++){
				if(i>0 && i<4 && j>1 && j<5 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i+2][j-2])) {
						if(haveAPreference(field[i+2][j-2])){
							field[i+2][j-2]= Math.abs(3 * field[i][j] * field[i+2][j-2]) * colorToInt(black);
						}else{
							field[i+2][j-2]=3*field[i][j];
						}
					}
					if (isEmpty(field[i-1][j+1])) {
						if(haveAPreference(field[i-1][j+1])){
							field[i-1][j+1]= Math.abs(3 * field[i][j] * field[i-1][j+1]) * colorToInt(black);
						}else{
							field[i-1][j+1]=3*field[i][j];
						}
					}
				}

				if(i==0 && j>1 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i+2][j-2])) {
						if(haveAPreference(field[i+2][j-2])){
							field[i+2][j-2]= Math.abs(3 * field[i][j] * field[i+2][j-2]) * colorToInt(black);
						}else{
							field[i+2][j-2]=3*field[i][j];
						}
					}
				}

				if(i==4 && j<5 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i-1][j+1])) {
						if(haveAPreference(field[i-1][j+1])){
							field[i-1][j+1]= Math.abs(3 * field[i][j] * field[i-1][j+1]) * colorToInt(black);
						}else{
							field[i-1][j+1]=3*field[i][j];
						}
					}
				}

				if(j==1 && i>0 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i-1][j+1])) {
						if(haveAPreference(field[i-1][j+1])){
							field[i-1][j+1]= Math.abs(3 * field[i][j] * field[i-1][j+1]) * colorToInt(black);
						}else{
							field[i-1][j+1]=3*field[i][j];
						}
					}
				}

				if(j==5 && i<4 && Math.abs(field[i][j])==1 && field[i][j] == field[i+1][j-1]){
					if (isEmpty(field[i+2][j-2])) {
						if(haveAPreference(field[i+2][j-2])){
							field[i+2][j-2]= Math.abs(3 * field[i][j] * field[i+2][j-2]) * colorToInt(black);
						}else{
							field[i+2][j-2]=3*field[i][j];
						}
					}
				}
			}
		}

	}




	public static void searchTwoOverThreeInARow(int[][] field, boolean black) {

		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 5; j++) {
				if ((j < 4)) {
					if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 2])) {
						if (isEmpty(field[i][j + 1])) {
							if(haveAPreference(field[i][j+1])){
								field[i][j+1]= Math.abs(3 * field[i][j] * field[i][j+1]) * colorToInt(black);
							}else{
								field[i][j+1]=3*field[i][j];
							}                        
						}
					}
				}
			}
		}
	}




	public static void searchTwoOverThreeInAColumn(int[][] field, boolean black) {

		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 6; j++) {
				if (i < 4) {
					if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 2][j])) {
						if (isEmpty(field[i + 1][j])) {
							if(haveAPreference(field[i+1][j])){
								field[i+1][j]= Math.abs(3 * field[i][j] * field[i+1][j]) * colorToInt(black);
							}else{
								field[i+1][j]=3*field[i][j];
							}
						}
					}
				}
			}
		}
	}




	public static void searchTwoOverThreeInADiagonal(int[][] field, boolean black) {

		for(int j = 0 ; j < 4 ; j++){
			for(int i = 0 ; i < 4 ; i++){
				if(Math.abs(field[i][j])==1 && field[i][j] == field[i+2][j+2]){
					if (isEmpty(field[i+1][j+1])) {
						if(haveAPreference(field[i+1][j+1])){
							field[i+1][j+1]= Math.abs(3 * field[i][j] * field[i+1][j+1]) * colorToInt(black);
						}else{
							field[i+1][j+1]=3*field[i][j];
						}
					}
				}

			}
		}

		for(int j = 5 ; j > 1 ; j--){
			for(int i = 0 ; i < 4 ; i++){
				if(Math.abs(field[i][j])==1 && field[i][j] == field[i+2][j-2]){
					if (isEmpty(field[i+1][j-1])) {
						if(haveAPreference(field[i+1][j-1])){
							field[i+1][j-1]= Math.abs(3 * field[i][j] * field[i+1][j-1]) * colorToInt(black);
						}else{
							field[i+1][j-1]=3*field[i][j];
						}
					}
				}

			}
		}
	}
	
	
   	

   	public static void searchPossibleFourInARow(int[][] field, boolean black) {

   		for (int i = 0; i < 6; i++) {
   			for (int j = 0; j < 4; j++) {
   				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1]) && (field[i][j + 1] == field[i][j + 2])) {
   					if (j==0 && isEmpty(field[i][j + 3]) && isEmpty(field[i][j + 4])){
   						if(haveAPreference(field[i][j + 3])){
   							field[i][j + 3] = Math.abs(18 * field[i][j] * field[i][j + 3]) * colorToInt(black);
   						}
   						else{
   							field[i][j + 3] = 18 * field[i][j];
   						}
   						if(haveAPreference(field[i][j + 4])){
   							field[i][j + 4] = Math.abs(18 * field[i][j] * field[i][j + 4]) * colorToInt(black);
   						}
   						else {
   							field[i][j + 4] = 18 * field[i][j];
   						}
   					}
   					
   					if (j==1) {
   						if(isEmpty(field[i][j - 1]) && isEmpty(field[i][j + 3])){
   							if(haveAPreference(field[i][j - 1])) {
   								field[i][j - 1] = Math.abs(18 * field[i][j] * field[i][j - 1]) * colorToInt(black);
   							}
   							else {
   								field[i][j - 1] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i][j + 3])) {
   								field[i][j + 3] = Math.abs(18 * field[i][j] * field[i][j + 3]) * colorToInt(black);
   							}
   							else {
   	   							field[i][j + 3] = 18 * field[i][j];
   	   						}
   						}
   						if (isEmpty(field[i][j + 3]) && isEmpty(field[i][j + 4])){
   							if(haveAPreference(field[i][j + 3])) {
   								field[i][j + 3] = Math.abs(18 * field[i][j] * field[i][j + 3]) * colorToInt(black);
   							}
   							else {
   								field[i][j + 3] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i][j + 4])) {
   								field[i][j + 4] = Math.abs(18 * field[i][j] * field[i][j + 4]) * colorToInt(black);
   							}
   							else {
   	   							field[i][j + 4] = 18 * field[i][j];
   	   						}
   						}
   					}
   					
   					if (j==2) {
   						if(isEmpty(field[i][j - 2]) && isEmpty(field[i][j - 1])){
   							if(haveAPreference(field[i][j - 2])) {
   								field[i][j - 2] = Math.abs(18 * field[i][j] * field[i][j - 2]) * colorToInt(black);
   							}
   							else {
   								field[i][j - 2] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i][j - 1])) {
   								field[i][j - 1] = Math.abs(18 * field[i][j] * field[i][j - 1]) * colorToInt(black);
   							}
   							else {
   	   							field[i][j - 1] = 18 * field[i][j];
   	   						}
   						}
   						if (isEmpty(field[i][j - 1]) && isEmpty(field[i][j + 3])){
   							if(haveAPreference(field[i][j - 1])) {
   								field[i][j - 1] = Math.abs(18 * field[i][j] * field[i][j - 1]) * colorToInt(black);
   							}
   							else {
   								field[i][j - 1] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i][j + 3])) {
   								field[i][j + 3] = Math.abs(18 * field[i][j] * field[i][j + 3]) * colorToInt(black);
   							}
   							else {
   	   							field[i][j + 3] = 18 * field[i][j];
   	   						}
   						}
   					}
   					
   					if (j==3 && isEmpty(field[i][j - 2]) && isEmpty(field[i][j - 1])){
   						if(haveAPreference(field[i][j - 2])) {
							field[i][j - 2] = Math.abs(18 * field[i][j] * field[i][j - 2]) * colorToInt(black);
						}
						else {
							field[i][j - 2] = 18 * field[i][j];
						}
						if(haveAPreference(field[i][j - 1])) {
							field[i][j - 1] = Math.abs(18 * field[i][j] * field[i][j - 1]) * colorToInt(black);
						}
						else {
	   						field[i][j - 1] = 18 * field[i][j];
	   					}
   					}

   				}
   			}
   			
   			for (int j = 0; j < 3; j++) {
   				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1]) && (field[i][j + 1] == field[i][j + 3])) {
   					
   					if (j==0 && isEmpty(field[i][j + 2]) && isEmpty(field[i][j + 4])){
   						if(haveAPreference(field[i][j + 2])) {
							field[i][j + 2] = Math.abs(18 * field[i][j] * field[i][j + 2]) * colorToInt(black);
						}
						else {
							field[i][j + 2] = 18 * field[i][j];
						}
						if(haveAPreference(field[i][j + 4])) {
							field[i][j + 4] = Math.abs(18 * field[i][j] * field[i][j + 4]) * colorToInt(black);
						}
						else {
	   						field[i][j + 4] = 18 * field[i][j];
	   					}
   					}
   					
   					if (j==1) {
   						if (isEmpty(field[i][j + 2]) && isEmpty(field[i][j - 1])) {
   							if(haveAPreference(field[i][j + 2])) {
   								field[i][j + 2] = Math.abs(18 * field[i][j] * field[i][j + 2]) * colorToInt(black);
   							}
   							else {
   								field[i][j + 2] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i][j - 1])) {
   								field[i][j - 1] = Math.abs(18 * field[i][j] * field[i][j - 1]) * colorToInt(black);
   							}
   							else {
   		   						field[i][j - 1] = 18 * field[i][j];
   		   					}
   						}
   						if (isEmpty(field[i][j + 2]) && isEmpty(field[i][j + 4])){
   							if(haveAPreference(field[i][j + 2])) {
   								field[i][j + 2] = Math.abs(18 * field[i][j] * field[i][j + 2]) * colorToInt(black);
   							}
   							else {
   								field[i][j + 2] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i][j + 4])) {
   								field[i][j + 4] = Math.abs(18 * field[i][j] * field[i][j + 4]) * colorToInt(black);
   							}
   							else {
   		   						field[i][j + 4] = 18 * field[i][j];
   		   					}
   						}
   					}
   					
   					if (j==2 && isEmpty(field[i][j + 2]) && isEmpty(field[i][j - 1])){
   						if(haveAPreference(field[i][j + 2])) {
							field[i][j + 2] = Math.abs(18 * field[i][j] * field[i][j + 2]) * colorToInt(black);
						}
						else {
							field[i][j + 2] = 18 * field[i][j];
						}
						if(haveAPreference(field[i][j - 1])) {
							field[i][j - 1] = Math.abs(18 * field[i][j] * field[i][j - 1]) * colorToInt(black);
						}
						else {
		   					field[i][j - 1] = 18 * field[i][j];
		   				}
   					}
   					
   				}
   				
   				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 2]) && (field[i][j + 2] == field[i][j + 3])) {	
   					if (j==0 && isEmpty(field[i][j + 1]) && isEmpty(field[i][j + 4])){
   						if(haveAPreference(field[i][j + 1])) {
							field[i][j + 1] = Math.abs(18 * field[i][j] * field[i][j + 1]) * colorToInt(black);
						}
						else {
							field[i][j + 1] = 18 * field[i][j];
						}
						if(haveAPreference(field[i][j + 4])) {
							field[i][j + 4] = Math.abs(18 * field[i][j] * field[i][j + 4]) * colorToInt(black);
						}
						else {
		   					field[i][j + 4] = 18 * field[i][j];
		   				}
   					}

   					if (j==1) {
   						if (isEmpty(field[i][j + 1]) && isEmpty(field[i][j - 1])) {
   							if(haveAPreference(field[i][j + 1])) {
   								field[i][j + 1] = Math.abs(18 * field[i][j] * field[i][j + 1]) * colorToInt(black);
   							}
   							else {
   								field[i][j + 1] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i][j - 1])) {
   								field[i][j - 1] = Math.abs(18 * field[i][j] * field[i][j - 1]) * colorToInt(black);
   							}
   							else {
   			   					field[i][j - 1] = 18 * field[i][j];
   			   				}
   						}
   						if(isEmpty(field[i][j + 1]) && isEmpty(field[i][j + 4])){
   							if(haveAPreference(field[i][j + 1])) {
   								field[i][j + 1] = Math.abs(18 * field[i][j] * field[i][j + 1]) * colorToInt(black);
   							}
   							else {
   								field[i][j + 1] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i][j + 4])) {
   								field[i][j + 4] = Math.abs(18 * field[i][j] * field[i][j + 4]) * colorToInt(black);
   							}
   							else {
   			   					field[i][j + 4] = 18 * field[i][j];
   			   				}
   						}
   					}
   					
   					if (j==2 && isEmpty(field[i][j + 1]) && isEmpty(field[i][j - 1])) {
   						if(haveAPreference(field[i][j + 1])) {
								field[i][j + 1] = Math.abs(18 * field[i][j] * field[i][j + 1]) * colorToInt(black);
							}
							else {
								field[i][j + 1] = 18 * field[i][j];
							}
							if(haveAPreference(field[i][j - 1])) {
								field[i][j - 1] = Math.abs(18 * field[i][j] * field[i][j - 1]) * colorToInt(black);
							}
							else {
			   					field[i][j - 1] = 18 * field[i][j];
			   				}
   					}
   				}
   			}
   		}
   	}
   	
   	
   	
   	

   	public static void searchPossibleFourInAColumn(int[][] field, boolean black) {

   		for (int i = 0; i < 4; i++) {
   			for (int j = 0; j < 6; j++) {
   				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j]) && (field[i + 1][j] == field[i + 2][j])) {
   					if (i==0 && isEmpty(field[i + 3][j]) && isEmpty(field[i + 4][j])){
   						if(haveAPreference(field[i + 3][j])) {
							field[i + 3][j] = Math.abs(18 * field[i][j] * field[i + 3][j]) * colorToInt(black);
						}
						else {
							field[i + 3][j] = 18 * field[i][j];
						}			
						if(haveAPreference(field[i + 4][j])) {
							field[i + 4][j] = Math.abs(18 * field[i][j] * field[i + 4][j]) * colorToInt(black);
						}
						else {
			   				field[i + 4][j] = 18 * field[i][j];
			   			}
   					}
   					
   					if (i==1) {
   						if(isEmpty(field[i - 1][j]) && isEmpty(field[i + 3][j])){
   							if(haveAPreference(field[i - 1][j])) {
   								field[i - 1][j] = Math.abs(18 * field[i][j] * field[i - 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i - 1][j] = 18 * field[i][j];
   							}			
   							if(haveAPreference(field[i + 3][j])) {
   								field[i + 3][j] = Math.abs(18 * field[i][j] * field[i + 3][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 3][j] = 18 * field[i][j];
   							}
   						}
   						if (isEmpty(field[i + 3][j]) && isEmpty(field[i + 4][j])){
   							if(haveAPreference(field[i + 3][j])) {
   								field[i + 3][j] = Math.abs(18 * field[i][j] * field[i + 3][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 3][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 4][j])) {
   								field[i + 4][j] = Math.abs(18 * field[i][j] * field[i + 4][j]) * colorToInt(black);
   							}
   							else {
   				   				field[i + 4][j] = 18 * field[i][j];
   				   			}
   						}
   					}
   					
   					if (i==2) {
   						if(isEmpty(field[i - 2][j]) && isEmpty(field[i -1][j])){
   							if(haveAPreference(field[i - 2][j])) {
   								field[i - 2][j] = Math.abs(18 * field[i][j] * field[i - 2][j]) * colorToInt(black);
   							}
   							else {
   								field[i - 2][j] = 18 * field[i][j];
   							}		
   							if(haveAPreference(field[i - 1][j])) {
   								field[i - 1][j] = Math.abs(18 * field[i][j] * field[i - 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i - 1][j] = 18 * field[i][j];
   							}
   						}
   						if (isEmpty(field[i - 1][j]) && isEmpty(field[i + 3][j])){
   							if(haveAPreference(field[i - 1][j])) {
   								field[i - 1][j] = Math.abs(18 * field[i][j] * field[i - 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i - 1][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 3][j])) {
   								field[i + 3][j] = Math.abs(18 * field[i][j] * field[i + 3][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 3][j] = 18 * field[i][j];
   							}
   						}
   					}
   					
   					if (i==3 && isEmpty(field[i - 2][j]) && isEmpty(field[i - 1][j])){
   						if(haveAPreference(field[i - 2][j])) {
							field[i - 2][j] = Math.abs(18 * field[i][j] * field[i - 2][j]) * colorToInt(black);
						}
						else {
							field[i - 2][j] = 18 * field[i][j];
						}			
						if(haveAPreference(field[i - 1][j])) {
							field[i - 1][j] = Math.abs(18 * field[i][j] * field[i - 1][j]) * colorToInt(black);
						}
						else {
							field[i - 1][j] = 18 * field[i][j];
						}
   					}
   				}
   			}
   		}

   		for(int i = 0 ; i < 3 ; i++){
   			for(int j = 0 ; j < 6 ; j++){
   				if((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j]) && (field[i + 1][j] == field[i + 3][j])){
   					if(i == 0){
   						if(isEmpty(field[i + 2][j]) && isEmpty(field[i + 4][j])){
   							if(haveAPreference(field[i + 2][j])) {
   								field[i + 2][j] = Math.abs(18 * field[i][j] * field[i + 2][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 2][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 4][j])) {
   								field[i + 4][j] = Math.abs(18 * field[i][j] * field[i + 4][j]) * colorToInt(black);
   							}
   							else {
   				   				field[i + 4][j] = 18 * field[i][j];
   				   			}
   						}
   					}

   					if(i == 1){
   						if(isEmpty(field[i + 2][j]) && isEmpty(field[i + 4][j])) {
   							if(haveAPreference(field[i + 2][j])) {
   								field[i + 2][j] = Math.abs(18 * field[i][j] * field[i + 2][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 2][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 4][j])) {
   								field[i + 4][j] = Math.abs(18 * field[i][j] * field[i + 4][j]) * colorToInt(black);
   							}
   							else {
   				   				field[i + 4][j] = 18 * field[i][j];
   				   			}
   						}
   						if(isEmpty(field[i + 2][j]) && isEmpty(field[i - 1][j])) {
   							if(haveAPreference(field[i + 2][j])) {
   								field[i + 2][j] = Math.abs(18 * field[i][j] * field[i + 2][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 2][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i - 1][j])) {
   								field[i - 1][j] = Math.abs(18 * field[i][j] * field[i - 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i - 1][j] = 18 * field[i][j];
   							}
   						}
   					}
   					
   					if(i == 2){
   						if(isEmpty(field[i - 1][j]) && isEmpty(field[i + 2][j])){
   							if(haveAPreference(field[i - 1][j])) {
   								field[i - 1][j] = Math.abs(18 * field[i][j] * field[i - 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i - 1][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 2][j])) {
   								field[i + 2][j] = Math.abs(18 * field[i][j] * field[i + 2][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 2][j] = 18 * field[i][j];
   							}
   						}
   					}

   				}
   				
   				if((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 2][j]) && (field[i + 2][j] == field[i + 3][j])){
   					
   					if(i == 0){
   						if(isEmpty(field[i + 1][j]) && isEmpty(field[i + 4][j])){
   							if(haveAPreference(field[i + 1][j])) {
   								field[i + 1][j] = Math.abs(18 * field[i][j] * field[i + 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 1][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 4][j])) {
   								field[i + 4][j] = Math.abs(18 * field[i][j] * field[i + 4][j]) * colorToInt(black);
   							}
   							else {
   				   				field[i + 4][j] = 18 * field[i][j];
   				   			}
   						}
   					}
   					if(i == 1){
   						if(isEmpty(field[i - 1][j]) && isEmpty(field[i + 1][j])){
   							if(haveAPreference(field[i - 1][j])) {
   								field[i - 1][j] = Math.abs(18 * field[i][j] * field[i - 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i - 1][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 1][j])) {
   								field[i + 1][j] = Math.abs(18 * field[i][j] * field[i + 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 1][j] = 18 * field[i][j];
   							}
   						}
   						if(isEmpty(field[i + 1][j]) && isEmpty(field[i + 4][j])){
   							if(haveAPreference(field[i + 1][j])) {
   								field[i + 1][j] = Math.abs(18 * field[i][j] * field[i + 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 1][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 4][j])) {
   								field[i + 4][j] = Math.abs(18 * field[i][j] * field[i + 4][j]) * colorToInt(black);
   							}
   							else {
   				   				field[i + 4][j] = 18 * field[i][j];
   				   			}
   						}
   					}
   					if(i == 2){
   						if(isEmpty(field[i - 1][j]) && isEmpty(field[i + 1][j])){
   							if(haveAPreference(field[i - 1][j])) {
   								field[i - 1][j] = Math.abs(18 * field[i][j] * field[i - 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i - 1][j] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[i + 1][j])) {
   								field[i + 1][j] = Math.abs(18 * field[i][j] * field[i + 1][j]) * colorToInt(black);
   							}
   							else {
   								field[i + 1][j] = 18 * field[i][j];
   							}
   						}
   					}
   				}
   			}
   		}
   	}


   	public static void searchPossibleFourInDiagonal_TopLeft(int[][] field, boolean black) {

   		// Analyzes principal diagonal
   		for (int i = 0; i < 5; i++) {
   			if (i!=2 && (Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (((Math.abs(field[1][1]) == 1) && field[i][i] == field[1][1]) && (Math.abs(field[4][4]) == 1) && field[i][i] == field[1][1])) {

   				if (i == 0 && i == 4) {
   					if (isEmpty(field[2][2]) && isEmpty(field[3][3])) {
   						if(haveAPreference(field[2][2])) {
							field[2][2] = Math.abs(18 * field[i][i] * field[2][2]) * colorToInt(black);
						}
						else {
							field[2][2] = 18 * field[i][i];
						}
   						if(haveAPreference(field[3][3])) {
							field[3][3] = Math.abs(18 * field[i][i] * field[3][3]) * colorToInt(black);
						}
						else {
							field[3][3] = 18 * field[i][i];
						}
   					}
   				}
   				
   				else if (i == 1){
   					if ((isEmpty(field[0][0]) && isEmpty(field[3][3]))){
   						if(haveAPreference(field[0][0])) {
							field[0][0] = Math.abs(18 * field[i][i] * field[0][0]) * colorToInt(black);
						}
						else {
							field[0][0] = 18 * field[i][i];
						}
   						if(haveAPreference(field[3][3])) {
							field[3][3] = Math.abs(18 * field[i][i] * field[3][3]) * colorToInt(black);
						}
						else {
							field[3][3] = 18 * field[i][i];
						}
   					}
   					if (isEmpty(field[3][3]) && isEmpty(field[5][5])){
   						if(haveAPreference(field[3][3])) {
							field[3][3] = Math.abs(18 * field[i][i] * field[3][3]) * colorToInt(black);
						}
						else {
							field[3][3] = 18 * field[i][i];
						}
   						if(haveAPreference(field[5][5])) {
							field[5][5] = Math.abs(18 * field[i][i] * field[5][5]) * colorToInt(black);
						}
						else {
							field[5][5] = 18 * field[i][i];
						}
   					}
   				}
   				
   				else if (i == 3){
   					if ((isEmpty(field[0][0]) && isEmpty(field[2][2]))){
   						if(haveAPreference(field[0][0])) {
							field[0][0] = Math.abs(18 * field[i][i] * field[0][0]) * colorToInt(black);
						}
						else {
							field[0][0] = 18 * field[i][i];
						}
   						if(haveAPreference(field[2][2])) {
							field[2][2] = Math.abs(18 * field[i][i] * field[2][2]) * colorToInt(black);
						}
						else {
							field[2][2] = 18 * field[i][i];
						}
   					}
   					if(isEmpty(field[2][2]) && isEmpty(field[5][5])){
   						if(haveAPreference(field[2][2])) {
							field[2][2] = Math.abs(18 * field[i][i] * field[2][2]) * colorToInt(black);
						}
						else {
							field[2][2] = 18 * field[i][i];
						}
   						if(haveAPreference(field[5][5])) {
							field[5][5] = Math.abs(18 * field[i][i] * field[5][5]) * colorToInt(black);
						}
						else {
							field[5][5] = 18 * field[i][i];
						}
   					}
   				}
   			}
   		}

   		
   		// Analyzes diagonal under principal
   		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[2][1]) && (field[1][0] == field[3][2])) {
   			if (isEmpty(field[4][3]) && isEmpty(field[5][4])) {
   				if(haveAPreference(field[4][3])) {
					field[4][3] = Math.abs(18 * field[1][0] * field[4][3]) * colorToInt(black);
				}
				else {
					field[4][3] = 18 * field[1][0];
				}
   				if(haveAPreference(field[5][4])) {
					field[5][4] = Math.abs(18 * field[1][0] * field[5][4]) * colorToInt(black);
				}
				else {
					field[5][4] = 18 * field[1][0];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[2][1]) && (field[1][0] == field[4][3])) {
   			if (isEmpty(field[3][2]) && isEmpty(field[5][4])) {
   				if(haveAPreference(field[3][2])) {
					field[3][2] = Math.abs(18 * field[1][0] * field[3][2]) * colorToInt(black);
				}
				else {
					field[3][2] = 18 * field[1][0];
				}
   				if(haveAPreference(field[5][4])) {
					field[5][4] = Math.abs(18 * field[1][0] * field[5][4]) * colorToInt(black);
				}
				else {
					field[5][4] = 18 * field[1][0];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[2][1]) && (field[1][0] == field[5][4])) {
   			if (isEmpty(field[3][2]) && isEmpty(field[4][3])) {
   				if(haveAPreference(field[3][2])) {
					field[3][2] = Math.abs(18 * field[1][0] * field[3][2]) * colorToInt(black);
				}
				else {
					field[3][2] = 18 * field[1][0];
				}
   				if(haveAPreference(field[4][3])) {
					field[4][3] = Math.abs(18 * field[1][0] * field[4][3]) * colorToInt(black);
				}
				else {
					field[4][3] = 18 * field[1][0];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[3][2]) && (field[1][0] == field[4][3])) {
   			if (isEmpty(field[2][1]) && isEmpty(field[5][4])) {
   				if(haveAPreference(field[2][1])) {
					field[2][1] = Math.abs(18 * field[1][0] * field[2][1]) * colorToInt(black);
				}
				else {
					field[2][1] = 18 * field[1][0];
				}
   				if(haveAPreference(field[5][4])) {
					field[5][4] = Math.abs(18 * field[1][0] * field[5][4]) * colorToInt(black);
				}
				else {
					field[5][4] = 18 * field[1][0];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[3][2]) && (field[1][0] == field[5][4])) {
   			if (isEmpty(field[2][1]) && isEmpty(field[4][3])) {
   				if(haveAPreference(field[2][1])) {
					field[2][1] = Math.abs(18 * field[1][0] * field[2][1]) * colorToInt(black);
				}
				else {
					field[2][1] = 18 * field[1][0];
				}
   				if(haveAPreference(field[4][3])) {
					field[4][3] = Math.abs(18 * field[1][0] * field[4][3]) * colorToInt(black);
				}
				else {
					field[4][3] = 18 * field[1][0];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][0]) == 1) && (field[1][0] == field[4][3]) && (field[1][0] == field[5][4])) {
   			if (isEmpty(field[2][1]) && isEmpty(field[3][2])) {
   				if(haveAPreference(field[2][1])) {
					field[2][1] = Math.abs(18 * field[1][0] * field[2][1]) * colorToInt(black);
				}
				else {
					field[2][1] = 18 * field[1][0];
				}
   				if(haveAPreference(field[3][2])) {
					field[3][2] = Math.abs(18 * field[1][0] * field[3][2]) * colorToInt(black);
				}
				else {
					field[3][2] = 18 * field[1][0];
				}
   			}
   		}
   		
   		if ((Math.abs(field[2][1]) == 1) && (field[2][1] == field[3][2]) && (field[2][1] == field[4][3])) {
   			if (isEmpty(field[1][0]) && isEmpty(field[5][4])) {
   				if(haveAPreference(field[1][0])) {
					field[1][0] = Math.abs(18 * field[2][1] * field[1][0]) * colorToInt(black);
				}
				else {
					field[1][0] = 18 * field[2][1];
				}
   				if(haveAPreference(field[5][4])) {
					field[5][4] = Math.abs(18 * field[2][1] * field[5][4]) * colorToInt(black);
				}
				else {
					field[5][4] = 18 * field[2][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[2][1]) == 1) && (field[2][1] == field[3][2]) && (field[2][1] == field[5][4])) {
   			if (isEmpty(field[1][0]) && isEmpty(field[4][3])) {
   				if(haveAPreference(field[1][0])) {
					field[1][0] = Math.abs(18 * field[2][1] * field[1][0]) * colorToInt(black);
				}
				else {
					field[1][0] = 18 * field[2][1];
				}
   				if(haveAPreference(field[4][3])) {
					field[4][3] = Math.abs(18 * field[2][1] * field[4][3]) * colorToInt(black);
				}
				else {
					field[4][3] = 18 * field[2][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[2][1]) == 1) && (field[2][1] == field[4][3]) && (field[2][1] == field[5][4])) {
   			if (isEmpty(field[1][0]) && isEmpty(field[3][2])) {
   				if(haveAPreference(field[1][0])) {
					field[1][0] = Math.abs(18 * field[2][1] * field[1][0]) * colorToInt(black);
				}
				else {
					field[1][0] = 18 * field[2][1];
				}
   				if(haveAPreference(field[3][2])) {
					field[3][2] = Math.abs(18 * field[2][1] * field[3][2]) * colorToInt(black);
				}
				else {
					field[3][2] = 18 * field[2][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[3][2]) == 1) && (field[3][2] == field[4][3]) && (field[3][2] == field[5][4])) {
   			if (isEmpty(field[1][0]) && isEmpty(field[2][1])) {
   				if(haveAPreference(field[1][0])) {
					field[1][0] = Math.abs(18 * field[3][2] * field[1][0]) * colorToInt(black);
				}
				else {
					field[1][0] = 18 * field[3][2];
				}
   				if(haveAPreference(field[3][2])) {
					field[2][1] = Math.abs(18 * field[3][2] * field[2][1]) * colorToInt(black);
				}
				else {
					field[2][1] = 18 * field[3][2];
				}
   			}
   		}
   		
   		
   		// Analyzes diagonal over principal
   		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[1][2]) && (field[0][1] == field[2][3])) {
   			if (isEmpty(field[3][4]) && isEmpty(field[4][5])) {
   				if(haveAPreference(field[3][4])) {
					field[3][4] = Math.abs(18 * field[0][1] * field[3][4]) * colorToInt(black);
				}
				else {
					field[3][4] = 18 * field[0][1];
				}
   				if(haveAPreference(field[4][5])) {
					field[4][5] = Math.abs(18 * field[0][1] * field[4][5]) * colorToInt(black);
				}
				else {
					field[4][5] = 18 * field[0][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[1][2]) && (field[0][1] == field[3][4])) {
   			if (isEmpty(field[2][3]) && isEmpty(field[4][5])) {
   				if(haveAPreference(field[2][3])) {
					field[2][3] = Math.abs(18 * field[0][1] * field[2][3]) * colorToInt(black);
				}
				else {
					field[2][3] = 18 * field[0][1];
				}
   				if(haveAPreference(field[4][5])) {
					field[4][5] = Math.abs(18 * field[0][1] * field[4][5]) * colorToInt(black);
				}
				else {
					field[4][5] = 18 * field[0][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[2][3]) && (field[0][1] == field[3][4])) {
   			if (isEmpty(field[1][2]) && isEmpty(field[4][5])) {
   				if(haveAPreference(field[1][2])) {
					field[1][2] = Math.abs(18 * field[0][1] * field[1][2]) * colorToInt(black);
				}
				else {
					field[1][2] = 18 * field[0][1];
				}
   				if(haveAPreference(field[4][5])) {
					field[4][5] = Math.abs(18 * field[0][1] * field[4][5]) * colorToInt(black);
				}
				else {
					field[4][5] = 18 * field[0][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[2][3]) && (field[0][1] == field[4][5])) {
   			if (isEmpty(field[1][2]) && isEmpty(field[3][4])) {
   				if(haveAPreference(field[1][2])) {
					field[1][2] = Math.abs(18 * field[0][1] * field[1][2]) * colorToInt(black);
				}
				else {
					field[1][2] = 18 * field[0][1];
				}
   				if(haveAPreference(field[3][4])) {
					field[3][4] = Math.abs(18 * field[0][1] * field[3][4]) * colorToInt(black);
				}
				else {
					field[3][4] = 18 * field[0][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[3][4]) && (field[0][1] == field[4][5])) {
   			if (isEmpty(field[1][2]) && isEmpty(field[2][3])) {
   				if(haveAPreference(field[1][2])) {
					field[1][2] = Math.abs(18 * field[0][1] * field[1][2]) * colorToInt(black);
				}
				else {
					field[1][2] = 18 * field[0][1];
				}
   				if(haveAPreference(field[2][3])) {
					field[2][3] = Math.abs(18 * field[0][1] * field[2][3]) * colorToInt(black);
				}
				else {
					field[2][3] = 18 * field[0][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][1]) == 1) && (field[0][1] == field[1][2]) && (field[0][1] == field[4][5])) {
   			if (isEmpty(field[2][3]) && isEmpty(field[3][4])) {
   				if(haveAPreference(field[2][3])) {
					field[2][3] = Math.abs(18 * field[0][1] * field[2][3]) * colorToInt(black);
				}
				else {
					field[2][3] = 18 * field[0][1];
				}
   				if(haveAPreference(field[3][4])) {
					field[3][4] = Math.abs(18 * field[0][1] * field[3][4]) * colorToInt(black);
				}
				else {
					field[3][4] = 18 * field[0][1];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][2]) == 1) && (field[1][2] == field[2][3]) && (field[1][2] == field[3][4])) {
   			if (isEmpty(field[0][1]) && isEmpty(field[4][5])) {
   				if(haveAPreference(field[0][1])) {
					field[0][1] = Math.abs(18 * field[1][2] * field[0][1]) * colorToInt(black);
				}
				else {
					field[0][1] = 18 * field[1][2];
				}
   				if(haveAPreference(field[4][5])) {
					field[4][5] = Math.abs(18 * field[1][2] * field[4][5]) * colorToInt(black);
				}
				else {
					field[4][5] = 18 * field[1][2];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][2]) == 1) && (field[1][2] == field[2][3]) && (field[1][2] == field[4][5])) {
   			if (isEmpty(field[0][1]) && isEmpty(field[3][4])) {
   				if(haveAPreference(field[0][1])) {
					field[0][1] = Math.abs(18 * field[1][2] * field[0][1]) * colorToInt(black);
				}
				else {
					field[0][1] = 18 * field[1][2];
				}
   				if(haveAPreference(field[3][4])) {
					field[3][4] = Math.abs(18 * field[1][2] * field[3][4]) * colorToInt(black);
				}
				else {
					field[3][4] = 18 * field[1][2];
				}
   			}
   		}
   		if ((Math.abs(field[1][2]) == 1) && (field[1][2] == field[3][4]) && (field[1][2] == field[4][5])) {
   			if (isEmpty(field[0][1]) && isEmpty(field[2][3])) {
   				if(haveAPreference(field[0][1])) {
					field[0][1] = Math.abs(18 * field[1][2] * field[0][1]) * colorToInt(black);
				}
				else {
					field[0][1] = 18 * field[1][2];
				}
   				if(haveAPreference(field[2][3])) {
					field[2][3] = Math.abs(18 * field[1][2] * field[2][3]) * colorToInt(black);
				}
				else {
					field[2][3] = 18 * field[1][2];
				}
   			}
   		}
   		
   		if ((Math.abs(field[2][3]) == 1) && (field[2][3] == field[3][4]) && (field[2][3] == field[4][5])) {
   			if (isEmpty(field[0][1]) && isEmpty(field[1][2])) {
   				if(haveAPreference(field[0][1])) {
					field[0][1] = Math.abs(18 * field[2][3] * field[0][1]) * colorToInt(black);
				}
				else {
					field[0][1] = 18 * field[2][3];
				}
   				if(haveAPreference(field[1][2])) {
					field[1][2] = Math.abs(18 * field[2][3] * field[1][2]) * colorToInt(black);
				}
				else {
					field[1][2] = 18 * field[2][3];
				}
   			}
   		}
   	}
   	
   	
   	
   	public static long searchPossibleFourInDiagonal_BelowLeft(int[][] field, boolean black) {
   		long value = 0;

   		// Analyzes secundary diagonal
   		for (int i = 0, j = 5; i < 5 && j > 0; i++, j--) {
   				if (i!=2 && (Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j - 1]) && (((Math.abs(field[1][4]) == 1) && field[i][j] == field[1][4]) && (Math.abs(field[4][1]) == 1) && field[i][j] == field[4][1])) {
   					if (i == 0 && i == 4) {
   						if (isEmpty(field[2][3]) && isEmpty(field[3][2])) {
   							if(haveAPreference(field[2][3])) {
   								field[2][3] = Math.abs(18 * field[i][j] * field[2][3]) * colorToInt(black);
   							}
   							else {
   								field[2][3] = 18 * field[i][j];
   							}
   			   				if(haveAPreference(field[3][2])) {
   								field[3][2] = Math.abs(18 * field[i][j] * field[3][2]) * colorToInt(black);
   							}
   							else {
   								field[3][2] = 18 * field[i][j];
   							}
   						}
   					} else if (i == 1) {
   						if ((isEmpty(field[0][5]) && isEmpty(field[3][2]))) {
   							if(haveAPreference(field[0][5])) {
   								field[0][5] = Math.abs(18 * field[i][j] * field[0][5]) * colorToInt(black);
   							}
   							else {
   								field[0][5] = 18 * field[i][j];
   							}
   			   				if(haveAPreference(field[3][2])) {
   								field[3][2] = Math.abs(18 * field[i][j] * field[3][2]) * colorToInt(black);
   							}
   							else {
   								field[3][2] = 18 * field[i][j];
   							}
   						}
   						if (isEmpty(field[3][2]) && isEmpty(field[5][0])){
   			   				if(haveAPreference(field[3][2])) {
   								field[3][2] = Math.abs(18 * field[i][j] * field[3][2]) * colorToInt(black);
   							}
   							else {
   								field[3][2] = 18 * field[i][j];
   							}
   			   				if(haveAPreference(field[5][0])) {
								field[5][0] = Math.abs(18 * field[i][j] * field[5][0]) * colorToInt(black);
							}
							else {
								field[5][0] = 18 * field[i][j];
							}
   						}
   					} else if (i == 3) {
   						if ((isEmpty(field[2][3]) && isEmpty(field[5][0]))) {
   							if(haveAPreference(field[2][3])) {
   								field[2][3] = Math.abs(18 * field[i][j] * field[2][3]) * colorToInt(black);
   							}
   							else {
   								field[2][3] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[5][0])) {
								field[5][0] = Math.abs(18 * field[i][j] * field[5][0]) * colorToInt(black);
							}
							else {
								field[5][0] = 18 * field[i][j];
							}
   						}
   						if (isEmpty(field[2][3]) && isEmpty(field[0][5])){
   							if(haveAPreference(field[2][3])) {
   								field[2][3] = Math.abs(18 * field[i][j] * field[2][3]) * colorToInt(black);
   							}
   							else {
   								field[2][3] = 18 * field[i][j];
   							}
   							if(haveAPreference(field[0][5])) {
   								field[0][5] = Math.abs(18 * field[i][j] * field[0][5]) * colorToInt(black);
   							}
   							else {
   								field[0][5] = 18 * field[i][j];
   							}
   						}
   					}
   				}
   			}
   		
   		
   		// Analyzes diagonal under secundary
   		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[2][4]) && (field[1][5] == field[3][3])) {
   			if (isEmpty(field[4][2]) && isEmpty(field[5][1])) {
   				if(haveAPreference(field[4][2])) {
					field[4][2] = Math.abs(18 * field[1][5] * field[4][2]) * colorToInt(black);
				}
				else {
					field[4][2] = 18 * field[1][5];
				}
				if(haveAPreference(field[5][1])) {
					field[5][1] = Math.abs(18 * field[1][5] * field[5][1]) * colorToInt(black);
				}
				else {
					field[5][1] = 18 * field[1][5];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[2][4]) && (field[1][5] == field[4][2])) {
   			if (isEmpty(field[3][3]) && isEmpty(field[5][1])) {
   				if(haveAPreference(field[3][3])) {
					field[3][3] = Math.abs(18 * field[1][5] * field[3][3]) * colorToInt(black);
				}
				else {
					field[3][3] = 18 * field[1][5];
				}
				if(haveAPreference(field[5][1])) {
					field[5][1] = Math.abs(18 * field[1][5] * field[5][1]) * colorToInt(black);
				}
				else {
					field[5][1] = 18 * field[1][5];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[2][4]) && (field[1][5] == field[5][1])) {
   			if (isEmpty(field[3][3]) && isEmpty(field[4][2])) {
   				if(haveAPreference(field[3][3])) {
					field[3][3] = Math.abs(18 * field[1][5] * field[3][3]) * colorToInt(black);
				}
				else {
					field[3][3] = 18 * field[1][5];
				}
				if(haveAPreference(field[4][2])) {
					field[4][2] = Math.abs(18 * field[1][5] * field[4][2]) * colorToInt(black);
				}
				else {
					field[4][2] = 18 * field[1][5];
				}
   			}
   		}

   		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[3][3]) && (field[1][5] == field[4][2])) {
   			if (isEmpty(field[2][4]) && isEmpty(field[5][1])) {
   				if(haveAPreference(field[2][4])) {
					field[2][4] = Math.abs(18 * field[1][5] * field[2][4]) * colorToInt(black);
				}
				else {
					field[2][4] = 18 * field[1][5];
				}
   				if(haveAPreference(field[5][1])) {
					field[5][1] = Math.abs(18 * field[1][5] * field[5][1]) * colorToInt(black);
				}
				else {
					field[5][1] = 18 * field[1][5];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[3][3]) && (field[1][5] == field[5][1])) {
   			if (isEmpty(field[2][4]) && isEmpty(field[4][2])) {
   				if(haveAPreference(field[2][4])) {
					field[2][4] = Math.abs(18 * field[1][5] * field[2][4]) * colorToInt(black);
				}
				else {
					field[2][4] = 18 * field[1][5];
				}
   				if(haveAPreference(field[4][2])) {
					field[4][2] = Math.abs(18 * field[1][5] * field[4][2]) * colorToInt(black);
				}
				else {
					field[4][2] = 18 * field[1][5];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][5]) == 1) && (field[1][5] == field[4][2]) && (field[1][5] == field[5][1])) {
   			if (isEmpty(field[2][4]) && isEmpty(field[3][3])) {
   				if(haveAPreference(field[2][4])) {
					field[2][4] = Math.abs(18 * field[1][5] * field[2][4]) * colorToInt(black);
				}
				else {
					field[2][4] = 18 * field[1][5];
				}
   				if(haveAPreference(field[3][3])) {
					field[3][3] = Math.abs(18 * field[1][5] * field[3][3]) * colorToInt(black);
				}
				else {
					field[3][3] = 18 * field[1][5];
				}
   			}
   		}

   		if ((Math.abs(field[2][4]) == 1) && (field[2][4] == field[3][3]) && (field[2][4] == field[4][2])) {
   			if (isEmpty(field[1][5]) && isEmpty(field[5][1])) {
   				if(haveAPreference(field[1][5])) {
					field[1][5] = Math.abs(18 * field[2][4] * field[1][5]) * colorToInt(black);
				}
				else {
					field[1][5] = 18 * field[2][4];
				}
   				if(haveAPreference(field[5][1])) {
					field[5][1] = Math.abs(18 * field[2][4] * field[5][1]) * colorToInt(black);
				}
				else {
					field[5][1] = 18 * field[2][4];
				}
   			}
   		}
   		
   		if ((Math.abs(field[2][4]) == 1) && (field[2][4] == field[3][3]) && (field[2][4] == field[5][1])) {
   			if (isEmpty(field[1][5]) && isEmpty(field[4][2])) {
   				if(haveAPreference(field[1][5])) {
					field[1][5] = Math.abs(18 * field[2][4] * field[1][5]) * colorToInt(black);
				}
				else {
					field[1][5] = 18 * field[2][4];
				}
   				if(haveAPreference(field[4][2])) {
					field[4][2] = Math.abs(18 * field[2][4] * field[4][2]) * colorToInt(black);
				}
				else {
					field[4][2] = 18 * field[2][4];
				}
   			}
   		}
   		
   		if ((Math.abs(field[2][4]) == 1) && (field[2][4] == field[4][2]) && (field[2][4] == field[5][1])) {
   			if (isEmpty(field[1][5]) && isEmpty(field[3][3])) {
   				if(haveAPreference(field[1][5])) {
					field[1][5] = Math.abs(18 * field[2][4] * field[1][5]) * colorToInt(black);
				}
				else {
					field[1][5] = 18 * field[2][4];
				}
   				if(haveAPreference(field[3][3])) {
					field[3][3] = Math.abs(18 * field[2][4] * field[3][3]) * colorToInt(black);
				}
				else {
					field[3][3] = 18 * field[2][4];
				}
   			}
   		}
   		
   		if ((Math.abs(field[3][3]) == 1) && (field[3][3] == field[4][2]) && (field[3][3] == field[5][1])) {
   			if (isEmpty(field[1][5]) && isEmpty(field[2][4])) {
   				if(haveAPreference(field[1][5])) {
					field[1][5] = Math.abs(18 * field[3][3] * field[1][5]) * colorToInt(black);
				}
				else {
					field[1][5] = 18 * field[3][3];
				}
   				if(haveAPreference(field[2][4])) {
					field[2][4] = Math.abs(18 * field[3][3] * field[2][4]) * colorToInt(black);
				}
				else {
					field[2][4] = 18 * field[3][3];
				}
   			}
   		}

   		
   		// Analyzes diagonal over secundary
   		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[1][3]) && (field[0][4] == field[2][2])) {
   			if (isEmpty(field[3][1]) && isEmpty(field[4][0])) {
   				if(haveAPreference(field[3][1])) {
					field[3][1] = Math.abs(18 * field[0][4] * field[3][1]) * colorToInt(black);
				}
				else {
					field[3][1] = 18 * field[0][4];
				}
   				if(haveAPreference(field[4][0])) {
					field[4][0] = Math.abs(18 * field[0][4] * field[4][0]) * colorToInt(black);
				}
				else {
					field[4][0] = 18 * field[0][4];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[1][3]) && (field[0][4] == field[3][1])) {
   			if (isEmpty(field[2][2]) && isEmpty(field[4][0])) {
   				if(haveAPreference(field[2][2])) {
					field[2][2] = Math.abs(18 * field[0][4] * field[2][2]) * colorToInt(black);
				}
				else {
					field[2][2] = 18 * field[0][4];
				}
   				if(haveAPreference(field[4][0])) {
					field[4][0] = Math.abs(18 * field[0][4] * field[4][0]) * colorToInt(black);
				}
				else {
					field[4][0] = 18 * field[0][4];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[1][3]) && (field[0][4] == field[4][0])) {
   			if (isEmpty(field[2][2]) && isEmpty(field[3][1])) {
   				if(haveAPreference(field[2][2])) {
					field[2][2] = Math.abs(18 * field[0][4] * field[2][2]) * colorToInt(black);
				}
				else {
					field[2][2] = 18 * field[0][4];
				}
   				if(haveAPreference(field[3][1])) {
					field[3][1] = Math.abs(18 * field[0][4] * field[3][1]) * colorToInt(black);
				}
				else {
					field[3][1] = 18 * field[0][4];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[2][2]) && (field[0][4] == field[3][1])) {
   			if (isEmpty(field[1][3]) && isEmpty(field[4][0])) {
   				if(haveAPreference(field[1][3])) {
					field[1][3] = Math.abs(18 * field[0][4] * field[1][3]) * colorToInt(black);
				}
				else {
					field[1][3] = 18 * field[0][4];
				}
   				if(haveAPreference(field[4][0])) {
					field[4][0] = Math.abs(18 * field[0][4] * field[4][0]) * colorToInt(black);
				}
				else {
					field[4][0] = 18 * field[0][4];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[2][2]) && (field[0][4] == field[4][0])) {
   			if (isEmpty(field[1][3]) && isEmpty(field[3][1])) {
   				if(haveAPreference(field[1][3])) {
					field[1][3] = Math.abs(18 * field[0][4] * field[1][3]) * colorToInt(black);
				}
				else {
					field[1][3] = 18 * field[0][4];
				}
   				if(haveAPreference(field[3][1])) {
					field[3][1] = Math.abs(18 * field[0][4] * field[3][1]) * colorToInt(black);
				}
				else {
					field[3][1] = 18 * field[0][4];
				}
   			}
   		}
   		
   		if ((Math.abs(field[0][4]) == 1) && (field[0][4] == field[3][1]) && (field[0][4] == field[4][0])) {
   			if (isEmpty(field[1][3]) && isEmpty(field[2][2])) {
   				if(haveAPreference(field[1][3])) {
					field[1][3] = Math.abs(18 * field[0][4] * field[1][3]) * colorToInt(black);
				}
				else {
					field[1][3] = 18 * field[0][4];
				}
   				if(haveAPreference(field[2][2])) {
					field[2][2] = Math.abs(18 * field[0][4] * field[2][2]) * colorToInt(black);
				}
				else {
					field[2][2] = 18 * field[0][4];
				}
   			}
   		}
   			
   		if ((Math.abs(field[1][3]) == 1) && (field[1][3] == field[2][2]) && (field[1][3] == field[3][1])) {
   			if (isEmpty(field[0][4]) && isEmpty(field[4][0])) {
   				if(haveAPreference(field[0][4])) {
					field[0][4] = Math.abs(18 * field[1][3] * field[0][4]) * colorToInt(black);
				}
				else {
					field[0][4] = 18 * field[1][3];
				}
   				if(haveAPreference(field[4][0])) {
					field[4][0] = Math.abs(18 * field[1][3] * field[4][0]) * colorToInt(black);
				}
				else {
					field[4][0] = 18 * field[1][3];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][3]) == 1) && (field[1][3] == field[2][2]) && (field[1][3] == field[4][0])) {
   			if (isEmpty(field[0][4]) && isEmpty(field[3][1])) {
   				if(haveAPreference(field[0][4])) {
					field[0][4] = Math.abs(18 * field[1][3] * field[0][4]) * colorToInt(black);
				}
				else {
					field[0][4] = 18 * field[1][3];
				}
   				if(haveAPreference(field[3][1])) {
					field[3][1] = Math.abs(18 * field[1][3] * field[3][1]) * colorToInt(black);
				}
				else {
					field[3][1] = 18 * field[1][3];
				}
   			}
   		}
   		
   		if ((Math.abs(field[1][3]) == 1) && (field[1][3] == field[3][1]) && (field[1][3] == field[4][0])) {
   			if (isEmpty(field[0][4]) && isEmpty(field[2][2])) {
   				if(haveAPreference(field[0][4])) {
					field[0][4] = Math.abs(18 * field[1][3] * field[0][4]) * colorToInt(black);
				}
				else {
					field[0][4] = 18 * field[1][3];
				}
   				if(haveAPreference(field[2][2])) {
					field[2][2] = Math.abs(18 * field[1][3] * field[2][2]) * colorToInt(black);
				}
				else {
					field[2][2] = 18 * field[1][3];
				}
   			}
   		}
   		
   		if ((Math.abs(field[2][2]) == 1) && (field[2][2] == field[3][1]) && (field[2][2] == field[4][0])) {
   			if (isEmpty(field[0][4]) && isEmpty(field[1][3])) {
   				if(haveAPreference(field[0][4])) {
					field[0][4] = Math.abs(18 * field[2][2] * field[0][4]) * colorToInt(black);
				}
				else {
					field[0][4] = 18 * field[2][2];
				}
   				if(haveAPreference(field[1][3])) {
					field[1][3] = Math.abs(18 * field[2][2] * field[1][3]) * colorToInt(black);
				}
				else {
					field[1][3] = 18 * field[2][2];
				}
   			}
   		}

   		return value;
   	}
   	
   	
	public static long searchPossibleFiveInARow(int[][] field, boolean black) {
		long value = 0;

		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 3; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i][j + 1]) && (field[i][j + 1] == field[i][j + 2]) && (field[i][j + 1] == field[i][j + 3])) {
					if (j==0 && isEmpty(field[i][j + 4])){
						if(haveAPreference(field[i][j + 4])){
							field[i][j + 4] = Math.abs(2100 * field[i][j] * field[i][j + 4]) * colorToInt(black);
						}else{
							field[i][j + 4] = 9015*field[i][j];
						}
					}

					if (j==1) {
						if(isEmpty(field[i][j - 1])){
							if(haveAPreference(field[i][j - 1])){
								field[i][j - 1] = Math.abs(2100 * field[i][j] * field[i][j - 1]) * colorToInt(black);
							}else{
								field[i][j - 1] = 2100*field[i][j];
							}
						}
						if (isEmpty(field[i][j + 4])){
							if(haveAPreference(field[i][j + 4])){
								field[i][j + 4] = Math.abs(2100 * field[i][j] * field[i][j + 4]) * colorToInt(black);
							}else{
								field[i][j + 4] = 2100*field[i][j];
							}
						}
					}

					if (j==2) {
						if(isEmpty(field[i][j - 1])){
							if(haveAPreference(field[i][j - 1])){
								field[i][j - 1] = Math.abs(2100 * field[i][j] * field[i][j - 1]) * colorToInt(black);
							}else{
								field[i][j - 1] = 2100*field[i][j];
							}
						}
					}
				}
			}
		}

		for(int i=0; i<5; i++){
			if((Math.abs(field[i][0]) == 1) && (field[i][0] == field[i][1]) && (field[i][0] == field[i][2]) && (field[i][0] == field[i][4])){
				if(isEmpty(field[i][3])){
					if(haveAPreference(field[i][3])){
						field[i][3] = Math.abs(2100 * field[i][0] * field[i][3]) * colorToInt(black);
					}else{
						field[i][3] = 2100*field[i][0];
					}
				}
			}

			if((Math.abs(field[i][0]) == 1) && (field[i][0] == field[i][1]) && (field[i][0] == field[i][3]) && (field[i][0] == field[i][4])){
				if(isEmpty(field[i][2])){
					if(haveAPreference(field[i][2])){
						field[i][2] = Math.abs(2100 * field[i][0] * field[i][2]) * colorToInt(black);
					}else{
						field[i][2] = 2100*field[i][0];
					}
				}
			}

			if((Math.abs(field[i][0]) == 1) && (field[i][0] == field[i][2]) && (field[i][0] == field[i][3]) && (field[i][0] == field[i][4])){
				if(isEmpty(field[i][1])){
					if(haveAPreference(field[i][1])){
						field[i][1] = Math.abs(2100 * field[i][0] * field[i][1]) * colorToInt(black);
					}else{
						field[i][1] = 2100*field[i][0];
					}
				}
			}

			if((Math.abs(field[i][1]) == 1) && (field[i][1] == field[i][2]) && (field[i][1] == field[i][3]) && (field[i][1] == field[i][5])){
				if(isEmpty(field[i][4])){
					if(haveAPreference(field[i][4])){
						field[i][4] = Math.abs(2100 * field[i][1] * field[i][4]) * colorToInt(black);
					}else{
						field[i][4] = 2100*field[i][1];
					}
				}
			}

			if((Math.abs(field[i][1]) == 1) && (field[i][1] == field[i][2]) && (field[i][1] == field[i][4]) && (field[i][1] == field[i][5])){
				if(isEmpty(field[i][3])){
					if(haveAPreference(field[i][3])){
						field[i][3] = Math.abs(2100 * field[i][1] * field[i][3]) * colorToInt(black);
					}else{
						field[i][3] = 2100*field[i][1];
					}
				}
			}

			if((Math.abs(field[i][1]) == 1) && (field[i][1] == field[i][3]) && (field[i][1] == field[i][4]) && (field[i][1] == field[i][5])){
				if(isEmpty(field[i][2])){
					if(haveAPreference(field[i][2])){
						field[i][2] = Math.abs(2100 * field[i][1] * field[i][2]) * colorToInt(black);
					}else{
						field[i][2] = 2100*field[i][1];
					}
				}
			}
		}

		return value;
	}
	
	

	public static long searchPossibleFiveInAColumn(int[][] field, boolean black) {
		long value = 0;

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 6; j++) {
				if ((Math.abs(field[i][j]) == 1) && (field[i][j] == field[i + 1][j]) && (field[i + 1][j] == field[i + 2][j]) && (field[i + 1][j] == field[i + 3][j])) {
					if (i==0 && isEmpty(field[i  + 4][j])){
						if(haveAPreference(field[i  + 4][j])){
							field[i  + 4][j] = Math.abs(2100 * field[i][j] * field[i  + 4][j]) * colorToInt(black);
						}else{
							field[i  + 4][j] = 2100*field[i][j];
						}
					}

					if (i==1) {
						if(isEmpty(field[i - 1][j])){
							if(haveAPreference(field[i - 1][j])){
								field[i - 1][j] = Math.abs(2100 * field[i][j] * field[i - 1][j]) * colorToInt(black);
							}else{
								field[i - 1][j] = 2100*field[i][j];
							}
						}
						if (isEmpty(field[i + 4][j])){
							if(haveAPreference(field[i  + 4][j])){
								field[i  + 4][j] = Math.abs(2100 * field[i][j] * field[i  + 4][j]) * colorToInt(black);
							}else{
								field[i  + 4][j] = 2100*field[i][j];
							}
						}
					}

					if (i==2) {
						if(isEmpty(field[i - 1][j])){
							if(haveAPreference(field[i - 1][j])){
								field[i - 1][j] = Math.abs(2100 * field[i][j] * field[i - 1][j]) * colorToInt(black);
							}else{
								field[i - 1][j] = 2100*field[i][j];
							}
						}
					}
				}
			}
		}

		for(int j = 0; j < 5; j++){
			if((Math.abs(field[0][j]) == 1) && (field[0][j] == field[1][j]) && (field[0][j] == field[2][j]) && (field[0][j] == field[4][j])){
				if(isEmpty(field[3][j])){
					if(haveAPreference(field[3][j])){
						field[3][j] = Math.abs(2100 * field[0][j] * field[3][j]) * colorToInt(black);
					}else{
						field[3][j] = 2100*field[0][j];
					}
				}
			}

			if((Math.abs(field[0][j]) == 1) && (field[0][j] == field[1][j]) && (field[0][j] == field[3][j]) && (field[0][j] == field[4][j])){
				if(isEmpty(field[2][j])){
					if(haveAPreference(field[2][j])){
						field[2][j] = Math.abs(2100 * field[0][j] * field[2][j]) * colorToInt(black);
					}else{
						field[2][j] = 2100*field[0][j];
					}
				}
			}

			if((Math.abs(field[0][j]) == 1) && (field[0][j] == field[2][j]) && (field[0][j] == field[3][j]) && (field[0][j] == field[4][j])){
				if(isEmpty(field[1][j])){
					if(haveAPreference(field[1][j])){
						field[1][j] = Math.abs(2100 * field[0][j] * field[1][j]) * colorToInt(black);
					}else{
						field[1][j] = 2100*field[0][j];
					}
				}
			}

			if((Math.abs(field[1][j]) == 1) && (field[1][j] == field[2][j]) && (field[1][j] == field[3][j]) && (field[1][j] == field[5][j])){
				if(isEmpty(field[4][j])){
					if(haveAPreference(field[4][j])){
						field[4][j] = Math.abs(2100 * field[1][j] * field[4][j]) * colorToInt(black);
					}else{
						field[4][j] = 2100*field[1][j];
					}
				}
			}

			if((Math.abs(field[1][j]) == 1) && (field[1][j] == field[2][j]) && (field[1][j] == field[4][j]) && (field[1][j] == field[5][j])){
				if(isEmpty(field[3][j])){
					if(haveAPreference(field[3][j])){
						field[3][j] = Math.abs(2100 * field[1][j] * field[3][j]) * colorToInt(black);
					}else{
						field[3][j] = 2100*field[1][j];
					}
				}
			}

			if((Math.abs(field[1][j]) == 1) && (field[1][j] == field[3][j]) && (field[1][j] == field[4][j]) && (field[1][j] == field[5][j])){
				if(isEmpty(field[2][j])){
					if(haveAPreference(field[2][j])){
						field[2][j] = Math.abs(2100 * field[1][j] * field[2][j]) * colorToInt(black);
					}else{
						field[2][j] = 2100*field[1][j];
					}
				}
			}
		}
		return value;
	}


	public static long searchPossibleFiveInADiagonal_TopLeft(int[][] field, boolean black) {
		long value = 0;


		for(int i = 0; i < 3; i++){
			if((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (field[i + 1][i + 1] == field[i + 2][i + 2]) && (field[i + 2][i + 2] == field[i + 3][i + 3])){
				if(i==0 && isEmpty(field[i + 4][i + 4])){
					if(haveAPreference(field[i + 4][i + 4])){
						field[i + 4][i + 4] = Math.abs(2100 * field[i][i] * field[i + 4][i + 4]) * colorToInt(black);
					}else{
						field[i + 4][i + 4] = 2100*field[i][i];
					}
				}


				if(i==1) {
					if(isEmpty(field[i - 1][i - 1])){
						if(haveAPreference(field[i - 1][i - 1])){
							field[i - 1][i - 1] = Math.abs(2100 * field[i][i] * field[i - 1][i - 1]) * colorToInt(black);
						}else{
							field[i - 1][i - 1] = 2100*field[i][i];
						}
					}
					if(isEmpty(field[i + 4][i + 4])){
						if(haveAPreference(field[i + 4][i + 4])){
							field[i + 4][i + 4] = Math.abs(2100 * field[i][i] * field[i + 4][i + 4]) * colorToInt(black);
						}else{
							field[i + 4][i + 4] = 2100*field[i][i];
						}
					}
				}


				if(i==2 && (isEmpty(field[i - 1][i - 1]))){
					if(haveAPreference(field[i - 1][i - 1])){
						field[i - 1][i - 1] = Math.abs(2100 * field[i][i] * field[i - 1][i - 1]) * colorToInt(black);
					}else{
						field[i - 1][i - 1] = 2100*field[i][i];
					}
				}
			}
		}

		for(int i = 0; i < 2; i++){
			if((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 2][i + 2]) && (field[i + 2][i + 2] == field[i + 3][i + 3]) && (field[i + 3][i + 3] == field[i + 4][i + 4])){
				if(isEmpty(field[i + 1][i + 1])){
					if(haveAPreference(field[i + 1][i + 1])){
						field[i + 1][i + 1] = Math.abs(2100 * field[i][i] * field[i + 1][i + 1]) * colorToInt(black);
					}else{
						field[i + 1][i + 1] = 2100*field[i][i];
					}
				}
			}

			if((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (field[i + 1][i + 1] == field[i + 3][i + 3]) && (field[i + 3][i + 3] == field[i + 4][i + 4])){
				if(isEmpty(field[i + 2][i + 2])){
					if(haveAPreference(field[i + 2][i + 2])){
						field[i + 2][i + 2] = Math.abs(2100 * field[i][i] * field[i + 2][i + 2]) * colorToInt(black);
					}else{
						field[i + 2][i + 2] = 2100*field[i][i];
					}
				}
			}

			if((Math.abs(field[i][i]) == 1) && (field[i][i] == field[i + 1][i + 1]) && (field[i + 1][i + 1] == field[i + 2][i + 2]) && (field[i + 2][i + 2] == field[i + 4][i + 4])){
				if(isEmpty(field[i + 3][i + 3])){
					if(haveAPreference(field[i + 3][i + 3])){
						field[i + 3][i + 3] = Math.abs(2100 * field[i][i] * field[i + 3][i + 3]) * colorToInt(black);
					}else{
						field[i + 3][i + 3] = 2100*field[i][i];
					}
				}
			}
		}

		return value;
	}




	public static long searchPossibleFiveInADiagonal_BelowLeft(int[][] field, boolean black) {
		long value = 0;

		/* 4 marble allineati sulla diagonale secondaria */
		if((Math.abs(field[5][0]) == 1) && (field[5][0] == field[4][1]) && (field[4][1] == field[3][2]) && (field[3][2] == field[2][3])){
			if(isEmpty(field[1][4])){
				if(haveAPreference(field[1][4])){
					field[1][4] = Math.abs(2100 * field[5][0] * field[1][4]) * colorToInt(black);
				}else{
					field[1][4] = 2100*field[5][0];
				}
			}
		}
		if((Math.abs(field[4][1]) == 1) && (field[4][1] == field[3][2]) && (field[3][2] == field[2][3]) && (field[2][3] == field[1][4])){
			if(isEmpty(field[5][0])){
				if(haveAPreference(field[5][0])){
					field[5][0] = Math.abs(2100 * field[4][1] * field[5][0]) * colorToInt(black);
				}else{
					field[5][0] = 2100*field[4][1];
				}
			}
			if(isEmpty(field[0][5])){
				if(haveAPreference(field[0][5])){
					field[0][5] = Math.abs(2100 * field[4][1] * field[0][5]) * colorToInt(black);
				}else{
					field[0][5] = 2100*field[4][1];
				}
			}
		}
		if((Math.abs(field[3][2]) == 1) && (field[3][2] == field[2][3]) && (field[2][3] == field[1][4]) && (field[1][4] == field[0][5])){
			if(isEmpty(field[4][1])){
				if(haveAPreference(field[4][1])){
					field[4][1] = Math.abs(2100 * field[3][2] * field[4][1]) * colorToInt(black);
				}else{
					field[4][1] = 2100*field[3][2];
				}
			}
		}


		/* 1 marble + spazio + 3 marble allineati sulla diagonale secondaria */
		if((Math.abs(field[5][0]) == 1) && (field[5][0] == field[3][2]) && (field[3][2] == field[2][3]) && (field[2][3] == field[1][4])){
			if(isEmpty(field[4][1])){
				if(haveAPreference(field[4][1])){
					field[4][1] = Math.abs(2100 * field[5][0] * field[4][1]) * colorToInt(black);
				}else{
					field[4][1] = 2100*field[5][0];
				}
			}
		}
		if((Math.abs(field[4][1]) == 1) && (field[4][1] == field[2][3]) && (field[2][3] == field[1][4]) && (field[1][4] == field[0][5])){
			if(isEmpty(field[3][2])){
				if(haveAPreference(field[3][2])){
					field[3][2] = Math.abs(2100 * field[4][1] * field[3][2]) * colorToInt(black);
				}else{
					field[3][2] = 2100*field[4][1];
				}
			}
		}


		/* 2 marble allineati + spazio + 2 marble allineati sulla diagonale secondaria */
		if((Math.abs(field[5][0]) == 1) && (field[5][0] == field[4][1]) && (field[4][1] == field[2][3]) && (field[2][3] == field[1][4])){
			if(isEmpty(field[3][2])){
				if(haveAPreference(field[3][2])){
					field[3][2] = Math.abs(2100 * field[5][0] * field[3][2]) * colorToInt(black);
				}else{
					field[3][2] = 2100*field[5][0];
				}
			}
		}
		if((Math.abs(field[4][1]) == 1) && (field[4][1] == field[3][2]) && (field[3][2] == field[1][4]) && (field[1][4] == field[0][5])){
			if(isEmpty(field[2][3])){
				if(haveAPreference(field[2][3])){
					field[2][3] = Math.abs(2100 * field[4][1] * field[2][3]) * colorToInt(black);
				}else{
					field[2][3] = 2100*field[4][1];
				}
			}
		}


		/* 3 marble allineati + spazio + 1 marble sulla diagonale secondaria */
		if((Math.abs(field[5][0]) == 1) && (field[5][0] == field[4][1]) && (field[4][1] == field[3][2]) && (field[3][2] == field[1][4])){
			if(isEmpty(field[2][3])){
				if(haveAPreference(field[2][3])){
					field[2][3] = Math.abs(2100 * field[5][0] * field[2][3]) * colorToInt(black);
				}else{
					field[2][3] = 2100*field[5][0];
				}
			}
		}
		if((Math.abs(field[4][1]) == 1) && (field[4][1] == field[3][2]) && (field[3][2] == field[2][3]) && (field[2][3] == field[0][5])){
			if(isEmpty(field[1][4])){
				if(haveAPreference(field[1][4])){
					field[1][4] = Math.abs(2100 * field[4][1] * field[1][4]) * colorToInt(black);
				}else{
					field[1][4] = 2100*field[4][1];
				}
			}
		}
		return value;
	}



	public static void searchPossibleFiveInADiagonal_TopLeft_UnderUpperMain(int[][] field, boolean black) {

		/** Controllo elementi sopra la diagonale principale **/
		if(isEmpty(field[0][1]) && Math.abs(field[1][2])==1 && field[1][2]==field[2][3] && field[1][2]==field[3][4] && field[1][2] == field[4][5]){
			if(haveAPreference(field[0][1])){
                field[0][1] = Math.abs(2100 * field[0][1] * field[1][2]) * colorToInt(black);
            }else{
                field[0][1] = 2100*field[1][2];
            }
		}

		if(isEmpty(field[1][2]) && Math.abs(field[0][1])==1 && field[0][1]==field[2][3] && field[0][1]==field[3][4] && field[0][1]==field[4][5]){
			if(haveAPreference(field[1][2])){
                field[1][2] = Math.abs(2100 * field[0][1] * field[1][2]) * colorToInt(black);
            }else{
                field[1][2] = 2100*field[0][1];
            }
		}

		if(isEmpty(field[2][3]) && Math.abs(field[0][1])==1 && field[0][1]==field[1][2] && field[0][1]==field[3][4] && field[0][1]==field[4][5]){
			if(haveAPreference(field[2][3])){
                field[2][3] = Math.abs(2100 * field[0][1] * field[2][3]) * colorToInt(black);
            }else{
                field[2][3] = 2100*field[0][1];
            }
		}

		if(isEmpty(field[3][4]) && Math.abs(field[0][1])==1 && field[0][1]==field[1][2] && field[0][1]==field[2][3] && field[0][1]==field[4][5]){
			if(haveAPreference(field[3][4])){
                field[3][4] = Math.abs(2100 * field[0][1] * field[3][4]) * colorToInt(black);
            }else{
                field[3][4] = 2100*field[0][1];
            }
		}

		if(isEmpty(field[4][5]) && Math.abs(field[0][1])==1 && field[0][1]==field[1][2] && field[0][1]==field[2][3] && field[0][1]==field[3][4]){
            if(haveAPreference(field[4][5])){
                field[4][5] = Math.abs(2100 * field[0][1] * field[4][5]) * colorToInt(black);
            }else{
                field[4][5] = 2100*field[0][1];
            }
		}

		/** Controllo elementi sotto la diagonale principale **/

		if(isEmpty(field[1][0]) && Math.abs(field[2][1])==1 && field[2][1]==field[3][2] && field[2][1]==field[4][3] && field[2][1] == field[5][4]){
			if(haveAPreference(field[1][0])){
                field[1][0] = Math.abs(2100 * field[2][1] * field[1][0]) * colorToInt(black);
            }else{
                field[1][0] = 2100*field[2][1];
            }
        }

		if(isEmpty(field[2][1]) && Math.abs(field[1][0])==1 && field[1][0]==field[3][2] && field[1][0]==field[4][3] && field[1][0]==field[5][4]){
            if(haveAPreference(field[2][1])){
                field[2][1] = Math.abs(2100 * field[1][0] * field[2][1]) * colorToInt(black);
            }else{
                field[2][1] = 2100*field[1][0];
            }
		}

		if(isEmpty(field[3][2]) && Math.abs(field[1][0])==1 && field[1][0]==field[2][1] && field[1][0]==field[4][3] && field[1][0]==field[5][4]){
            if(haveAPreference(field[3][2])){
                field[3][2] = Math.abs(2100 * field[1][0] * field[3][2]) * colorToInt(black);
            }else{
                field[3][2] = 2100*field[1][0];
            }
		}

		if(isEmpty(field[4][3]) && Math.abs(field[1][0])==1 && field[1][0]==field[2][1] && field[1][0]==field[3][2] && field[1][0]==field[5][4]){
            if(haveAPreference(field[4][3])){
                field[4][3] = Math.abs(2100 * field[1][0] * field[4][3]) * colorToInt(black);
            }else{
                field[4][3] = 2100*field[1][0];
            }
		}

		if(isEmpty(field[5][4]) && Math.abs(field[1][0])==1 && field[1][0]==field[2][1] && field[1][0]==field[3][2] && field[1][0]==field[4][3]){
			if(haveAPreference(field[5][4])){
                field[5][4] = Math.abs(2100 * field[1][0] * field[5][4]) * colorToInt(black);
            }else{
                field[5][4] = 2100*field[1][0];
            }
		}
	}




	public static void searchPossibleFiveInADiagonal_BelowLeft_UnderUpperMain(int[][] field, boolean black) {

		/**Controllo elementi sotto la diagonale secondaria**/
		if(isEmpty(field[5][1]) && Math.abs(field[4][2])==1 && field[4][2]==field[3][3] && field[4][2]==field[2][4] && field[4][2]==field[1][5]){
            if(haveAPreference(field[5][1])){
                field[5][1] = Math.abs(2100 * field[4][2] * field[5][1]) * colorToInt(black);
            }else{
                field[5][1] = 2100*field[4][2];
            }
		}

		if(isEmpty(field[4][2]) && Math.abs(field[5][1])==1 && field[5][1]==field[3][3] && field[5][1]==field[2][4] && field[5][1]==field[1][5]){
			if(haveAPreference(field[4][2])){
                field[4][2] = Math.abs(2100 * field[5][1] * field[4][2]) * colorToInt(black);
            }else{
                field[4][2] = 2100*field[5][1];
            }
		}

		if(isEmpty(field[3][3]) && Math.abs(field[5][1])==1 && field[5][1]==field[4][2] && field[5][1]==field[2][4] && field[5][1]==field[1][5]){
			if(haveAPreference(field[3][3])){
                field[3][3] = Math.abs(2100 * field[5][1] * field[3][3]) * colorToInt(black);
            }else{
                field[3][3] = 2100*field[5][1];
            }
		}

		if(isEmpty(field[2][4]) && Math.abs(field[5][1])==1 && field[5][1]==field[4][2] && field[5][1]==field[3][3] && field[5][1]==field[1][5]){
			if(haveAPreference(field[2][4])){
                field[2][4] = Math.abs(2100 * field[5][1] * field[2][4]) * colorToInt(black);
            }else{
                field[2][4] = 2100*field[5][1];
            }
        }

		if(isEmpty(field[1][5]) && Math.abs(field[5][1])==1 && field[5][1]==field[4][2] && field[5][1]==field[3][3] && field[5][1]==field[2][4]){
			if(haveAPreference(field[1][5])){
                field[1][5] = Math.abs(2100 * field[5][1] * field[1][5]) * colorToInt(black);
            }else{
                field[1][5] = 2100*field[5][1];
            }
		}

		/**Controllo elementi sopra la diagonale secondaria**/
		if(isEmpty(field[0][4]) && Math.abs(field[1][3])==1 && field[1][3]==field[2][2] && field[1][3]==field[3][1] && field[1][3]==field[4][0]){
			if(haveAPreference(field[0][4])){
                field[0][4] = Math.abs(2100 * field[1][3] * field[0][4]) * colorToInt(black);
            }else{
                field[0][4] = 2100*field[1][3];
            }
		}

		if(isEmpty(field[1][3]) && Math.abs(field[0][4])==1 && field[0][4]==field[2][2] && field[0][4]==field[3][1] && field[0][4]==field[4][0]){
			if(haveAPreference(field[1][3])){
                field[1][3] = Math.abs(2100 * field[0][4] * field[1][3]) * colorToInt(black);
            }else{
                field[1][3] = 2100*field[0][4];
            }
		}

		if(isEmpty(field[2][2]) && Math.abs(field[0][4])==1 && field[0][4]==field[1][3] && field[0][4]==field[3][1] && field[0][4]==field[4][0]){
			if(haveAPreference(field[2][2])){
                field[2][2] = Math.abs(2100 * field[0][4] * field[2][2]) * colorToInt(black);
            }else{
                field[2][2] = 2100*field[0][4];
            }
		}

		if(isEmpty(field[3][1]) && Math.abs(field[0][4])==1 && field[0][4]==field[1][3] && field[0][4]==field[2][2] && field[0][4]==field[4][0]){
			if(haveAPreference(field[3][1])){
                field[3][1] = Math.abs(2100 * field[0][4] * field[3][1]) * colorToInt(black);
            }else{
                field[3][1] = 2100*field[0][4];
            }
		}

		if(isEmpty(field[4][0]) && Math.abs(field[0][4])==1 && field[0][4]==field[1][3] && field[0][4]==field[3][1] && field[0][4]==field[2][2]){
			if(haveAPreference(field[4][0])){
                field[4][0] = Math.abs(2100 * field[0][4] * field[4][0]) * colorToInt(black);
            }else{
                field[4][0] = 2100*field[0][4];
            }
		}

	}
   	
   	
   	
   	
   	public static void fullJudge(int[][] field, boolean black) {

		// Possibili 3
		searchTwoInARow(field, black);
		searchTwoInAColumn(field, black);
		searchTwoInADiagonal(field, black);
		searchTwoOverThreeInARow(field, black);
		searchTwoOverThreeInAColumn(field, black);
		searchTwoOverThreeInADiagonal(field, black);

		// Possibili 4
		searchPossibleFourInARow(field, black);
		searchPossibleFourInAColumn(field, black);
		searchPossibleFourInDiagonal_TopLeft(field, black);
		searchPossibleFourInDiagonal_BelowLeft(field, black);

		// Possibili 5
		searchPossibleFiveInARow(field, black);
		searchPossibleFiveInAColumn(field, black);
		searchPossibleFiveInADiagonal_TopLeft(field, black);
		searchPossibleFiveInADiagonal_TopLeft_UnderUpperMain(field, black);
		searchPossibleFiveInADiagonal_BelowLeft(field, black);
		searchPossibleFiveInADiagonal_BelowLeft_UnderUpperMain(field, black);
   	}

   	
   	

   	/**
   	 * A modified version of the rotate method from the GameEngine.Board
   	 * 
   	 * see GameEngine.Board.rotate
   	 *
   	 * @param board current array
   	 * @param quadrant which is supposed to be rotated
   	 * @param clock true for a right rotation, false for a left retation
   	 * @return new rotated board
   	 */
   	public static int[][] rotate(int[][] board, int quadrant, int clock) {
   		boolean clockwise = false;
   		int[][] rotatedBoard = new int[6][6];
   		int[][] singleQuadranRotatedBoard = new int[6][6];
   		int startX=0, startY=0, endX = 0, endY=0, clockwiseRotation=0, counterClockWise=0, counterClockWiseRefresh=0, rotatingCol=0;

   		fill(board, rotatedBoard);

   		if(clock==1){
   			clockwise = true;
   		}

   		//setting parameters sub rotation
   		if(quadrant == 1){
   			clockwiseRotation=0;
   			counterClockWise=0;
   			counterClockWiseRefresh=0;
   			rotatingCol=3;
   			startX=0;
   			startY=0;
   			endX=3;
   			endY=3;
   		}else if (quadrant==2){
   			clockwiseRotation=3;
   			counterClockWise=0;
   			counterClockWiseRefresh=0;
   			rotatingCol=6;
   			startX=0;
   			startY=3;
   			endX=3;
   			endY=6;
   		}else if (quadrant==3){
   			clockwiseRotation=0;
   			counterClockWise=3;
   			counterClockWiseRefresh=3;
   			rotatingCol=6;
   			startX=3;
   			startY=0;
   			endX=6;
   			endY=3;
   		}else{
   			clockwiseRotation=3;
   			counterClockWise=3;
   			counterClockWiseRefresh=3;
   			rotatingCol=9;
   			startX=3;
   			startY=3;
   			endX=6;
   			endY=6;
   		}

   		if(clockwise){
   			for (int i = startX; i < endX; ++i) {
   				for (int j = startY; j < endY; ++j) {
   					singleQuadranRotatedBoard[i][j] = rotatedBoard[rotatingCol - j - 1][clockwiseRotation];
   				}
   				clockwiseRotation++;
   			}

   		}else{
   			for (int i = startX; i < endX; ++i) {
   				for (int j = startY; j < endY; ++j) {
   					singleQuadranRotatedBoard[i][j] = rotatedBoard[counterClockWise][rotatingCol - i - 1];
   					counterClockWise++;
   				}
   				counterClockWise=counterClockWiseRefresh;
   			}
   		}

   		for (int i = startX; i < endX; ++i) {
   			for (int j = startY; j < endY; ++j) {
   				rotatedBoard[i][j] = singleQuadranRotatedBoard[i][j];
   			}
   		}

   		return rotatedBoard;
   	}

   	
   	/**
   	 * This method copys on cell from a array into an other,
   	 *
   	 * @param field
   	 * @param tofillup
   	 */
   	public static void fill(int[][] field, int[][] tofillup) {
   		for (int i = 0; i < 6; i++) {
   			for (int j = 0; j < 6; j++) {
   				tofillup[i][j] = field[i][j];
   			}
   		}
   	}


   	/**
   	 * Shows if the player flag who got a winning situation in a Column
   	 * @param board
   	 * @param who
   	 * @return boolean if win = true else false
   	 */
   	public static boolean checkWinColumn(int[][] board, boolean who) {

   		int temp = 1;
   		if(who)
   			temp = -1;
   		for (int i = 0; i < 6; i++) {
   			/*initialize sum with 0*/
   			int sum = 0;
   			for (int j = 0; j < 6; j++) {
   					if (board[j][i] == temp) {
   						sum += board[j][i];
   					} else {
   						sum = 0;
   					}
   					if (Math.abs(sum) == 5) {
   						return true;
   					}
   			}
   		}
   		return false;
   	}

   	
   	/**
   	 * This function calculates the sum of the rows
   	 * @param who This parameter shows who is playing. If who = true, Black plays, else White plays
   	 * @param board is the targetarray
   	 * @return true if there is a wining situation on board
   	 */
   	public static boolean checkWinRow(int[][] board, boolean who) {

   		int temp = 1;
   		if(who)
   			temp = -1;
   		for (int i = 0; i < 6; i++) {
   			/*initialize sum with 0*/
   			int sum = 0;
   			for (int j = 0; j < 6; j++) {
   					if (board[i][j] == temp) {
   						sum += board[i][j];
   					} else {
   						sum = 0;
   					}
   					if (Math.abs(sum) == 5) {
   						return true;
   					}
   			}
   		}
   		return false;
   	}

   	
   	/**
   	 * This function calculates the sum of the 3 second diagonals
   	 * @param who This parameter shows who is playing. If who = true, Black plays, else White plays
   	 * @param board is the targetarray
   	 * @return true if there is a wining situation on board
   	 */
   	public static boolean checkWinSecondDiag(int[][] board, boolean who) {
   		
   		int temp = 1;
   		if(who)
   			temp = -1;
   		int sum = 0;
   		/*Diagonal from 0|5 to 5|0*/
   		for (int i = 0; i < 6; i++) {
   			int j = 5 - i;
   				if (board[j][i] == temp) {
   					sum += board[j][i];
   				} else {
   					sum = 0;
   				}
   				if (Math.abs(sum) == 5) {
   					return true;
   				}
   		}

   		/*Diagonal from 0|4 to 4|0*/
   		sum = 0;
   		for (int i = 0; i < 5; i++) {
   			int j = 4 - i;
   				if (board[j][i] == temp) {
   					sum += board[j][i];
   				} else {
   					sum = 0;
   				}
   				if (Math.abs(sum) == 5) {
   					return true;
   				}
   		}

   		/*Diagonal from 1|5 to 5|1*/
   		sum = 0;
   		for (int i = 1; i < 6; i++) {
   			int j = 6 - i;
   				if (board[i][j] == temp) {
   					sum += board[i][j];
   				} else {
   					sum = 0;
   				}
   				if (Math.abs(sum) == 5) {
   					return true;
   				}
   		}
   		return false;

   	}

   	
   	/**
   	 * This function calculates the sum of the 3 diagonals
   	 * @param who This parameter shows who is playing. If who = true, Black plays, else White plays
   	 * @param board is the targetarray
   	 * @return true if there is a wining situation on board
   	 */
   	public static boolean checkWinMainDiag(int[][] board, boolean who) {

   		int temp = 1;
   		if(who)
   			temp = -1;
   		/*Diagonal from 0|0 to 5|5*/

   		/*initialize sum with 0*/
   		int sum = 0;
   		for (int i = 0; i < 6; i++) {

   				if (board[i][i] == temp) {
   					sum += board[i][i];
   				} else {
   					sum = 0;
   				}
   				if (Math.abs(sum) == 5) {
   					return true;
   				}
   		}

   		/*Diagonal from 0|1 to 4|5*/

   		/*initialize sum with 0*/
   		sum = 0;
   		for (int i = 0; i < 5; i++) {

   				if (board[i + 1][i] == temp) {
   					sum += board[i + 1][i];
   				} else {
   					sum = 0;
   				}
   				if (Math.abs(sum) == 5) {
   					return true;
   				}
   		}

   		/*Diagonal from 1|0 to 5|4*/

   		/*initialize sum with 0*/
   		sum = 0;
   		for (int i = 0; i < 5; i++) {

   				if (board[i][i + 1] == temp) {
   					sum += board[i][i + 1];
   				} else {
   					sum = 0;
   				}
   				if (Math.abs(sum) == 5) {
   					return true;
   				}
   		}
   		return false;

   	}

   	
   	/**
   	 * A modified version of the checkWin method from the GameEngine.Board
   	 *
   	 * @param board is the board that is supposed to be checked
   	 * @param who palyerflag
   	 * @return true if ther are 5 equal merbels in a row,column or diagnal oterwise false
   	 */
   	public static boolean checkWin(int[][] board, boolean who) {
   		if (checkWinRow(board, who) == true) {
   			return true;
   		}

   		if (checkWinColumn(board, who) == true) {
   			return true;
   		}

   		if (checkWinMainDiag(board, who) == true) {
   			return true;
   		}

   		if (checkWinSecondDiag(board, who) == true) {
   			return true;
   		}

   		return false;
   	}
   	
   	
}